package com.ptszyxx.popose.module.main.map.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.utils.YUserUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseListResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessListResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.home.HomeResult;

import java.util.HashMap;
import java.util.Map;

public class MapVM extends BaseViewModel<CommonRepository> {
    public String userId, txUserId;

    public MapVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        public SingleLiveEvent onRefreshEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onStartLocationEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onStartLocationCommand = new BindingCommand(()-> uc.onStartLocationEvent.call());

    /**
     *
     */
    public void requestMapList(String address){
        Map<String, String> map = new HashMap<>();
        map.put("address", address);

        HttpUtils.getInstance()
                .list(model.mapList(map), this,
                        new OnSuccessListResult<HomeResult>() {
                            @Override
                            public void onSuccessResult(BaseListResponse<HomeResult> response) {
                                uc.onRefreshEvent.setValue(response.getData());
                            }
                        });
    }








}
